import wx_opendata from "./wx/wx_opendata";
import constants from "./constants";
import global from "./global";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

 
    @property(cc.Node)
    closeBtn:cc.Node=null;

    @property(cc.Node)
    subView:cc.Node=null;

    @property(cc.Node)
    groupBtn:cc.Node=null;

    @property(cc.Node)
    startBtn:cc.Node=null;
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
        this.subView.getComponent(cc.Widget).updateAlignment();
        let data;
        switch(global.rankingState){
            case global.RankingState.Group:
            data={action:wx_opendata.WxDomainAction.FetchGroup,shareTicket:global.shareTicket};
            this.groupBtn.active=false;
            this.startBtn.active=true;
            this.closeBtn.active=false;
            break;
            case global.RankingState.Friend:
            data={action:wx_opendata.WxDomainAction.FetchFriend};
            this.groupBtn.active=true;
            this.startBtn.active=false;
            this.closeBtn.active=true;
            break;
        }
        wx_opendata.wxPostMessageToSubDomain({
            ...data,
            width:this.subView.width,
            height:this.subView.height
        });
    }

    onClickClose(){
        cc.director.loadScene(global.rankingCallBackScene);
    }

    onClickShareGroup(){
      cc.director.emit(constants.GAME_EVENT.BtnClick);
      wx_opendata.wxShare();
    }

    // update (dt) {}
}
